package org.example.course.template;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.example.commonapi.dto.CourseInfoDto;
import org.example.commonapi.dto.PageInfo;

public abstract class AbstractCourseQueryTemplate {

    public final PageInfo executeQuery(Integer pageNum, Integer pageSize,
                                       Integer state, String courseName, Long id) {
        // 公共预处理
        Page<CourseInfoDto> page = new Page<>(pageNum, pageSize);

        // 调用具体实现
        IPage<CourseInfoDto> result = doQuery(page, state, courseName, id);

        // 公共后处理
        return new PageInfo(result);
    }

    protected abstract IPage<CourseInfoDto> doQuery(Page<CourseInfoDto> page,
                                                    Integer state,
                                                    String courseName,
                                                    Long id);
}
